package com.zgd.util;
import com.mchange.v2.c3p0.ComboPooledDataSource;

import javax.sql.DataSource;
import java.sql.*;


public class JDBCTool {
   private static DataSource ds;
   static{
       ds = new ComboPooledDataSource("testc3p0");
    }
    public static Connection getConnection(){
      Connection conn = null;
        try {
            conn = ds.getConnection();
        } catch (SQLException e) {
           e.printStackTrace();
        }
            return conn;
    }
    public static void release(Connection conn, Statement stmt, ResultSet rs){
      try {
          if (conn != null) {
              conn.close();
          }
          if (stmt != null) {
              stmt.close();
          }
          if (rs != null) {
              rs.close();
          }
      }catch (SQLException e) {
          e.printStackTrace();
      }

    }
}
